import subprocess
import time

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('-i', dest='ips', help='ips')
    parser.add_argument('-t', dest='thr', help='thr')
    parser.add_argument('-p', dest='port', help='thr')
    args = parser.parse_args()
    assert args.ips is not None
    if args.thr is None:
        args.thr = 2000

    a = args.ips.split("-")
    if len(a) == 1:
        cmd = "sudo masscan {}.0.0.0/8 -p {} --rate {}  -oL {} --excludefile ../dic/exclude.txt ".format(a[0], args.port, args.thr, a[0])
        subprocess.call(cmd, shell=True)
        time.sleep(30)
        git = "sh gitpull.sh {}".format(a[0])
        subprocess.call(git, shell=True)
    else:
        for i in range(int(a[0]), int(a[1]) + 1, 1):
            cmd = "sudo masscan {}.0.0.0/8 -p {} --rate {}  -oL {} --excludefile ../dic/exclude.txt".format(i, args.port, args.thr, i)
            subprocess.call(cmd, shell=True)
            time.sleep(30)
            git = "sh gitpull.sh {}".format(i)
            subprocess.call(git, shell=True)
